package com.googlecode.bip.entity.impl;

import java.sql.Timestamp;
import java.util.List;
import com.googlecode.bip.entity.IQuestion;
import com.googlecode.bip.entity.IQuestionValue;
import com.googlecode.bip.entity.IUserValue;
import com.googlecode.bip.entity.IllegalValueException;

public class QuestionValue implements IQuestionValue
{
    private static final long serialVersionUID = 1L;

    private IQuestion question;
    private IUserValue userValue;

    public QuestionValue()
    {
        this( new Question(), new UserValue() );
    }

    public QuestionValue( IQuestion q, IUserValue v )
    {
        if( q == null ) {
            throw new NullPointerException( "IQuestion is null" );
            }
        if( v == null ) {
           throw new NullPointerException( "IUserValue is null" );
        }
        if( q.getIdQuestion() != v.getIdQuestion() ) {
            // idquestion are not consistent
            throw new IllegalArgumentException( "idquestion are not consistent" );
            }
        question  = q;
        userValue = v;
    }

    @Override // ISurveyEntry
    public boolean isIQuestion()
    {
        return true;
    }
    @Override // ISurveyEntry
    public boolean isITopic()
    {
        return false;
    }
    @Override // ISurveyEntry
    public boolean isISurveyMetaData()
    {
        return false;
    }

    @Override // IUserValue
    public int getIdUser()
    {
        return userValue.getIdUser();
    }
    @Override // IUserValue
    public void setIdUser(int iduser)
    {
        userValue.setIdUser(iduser);
    }
    @Override // IUserValue
    public Timestamp getUserDate()
    {
        return userValue.getUserDate();
    }
    @Override // IUserValue
    public void setUserDate(Timestamp userDate)
    {
        userValue.setUserDate(userDate);
    }
    @Override // IUserValue
    public Integer getUserValue()
    {
        return userValue.getUserValue();
    }
    @Override // IUserValue
    public void setUserValue(Integer userValue)
    {
    	if (userValue != null) {
            this.userValue.setUserValue(userValue);
    	}
    }
    @Override // IUserValue
    public String getUserComment()
    {
        return userValue.getUserComment();
    }
    @Override // IUserValue
    public void setUserComment(String userComment)
    {
        userValue.setUserComment(userComment);
    }

    @Override // IUserValue & IQuestion
    public int getIdQuestion()
    {
        return question.getIdQuestion();
    }
    @Override // IUserValue & IQuestion
    public void setIdQuestion(int idquestion)
    {
        question.setIdQuestion(idquestion);
        userValue.setIdQuestion(idquestion);
    }

    @Override // IQuestion
    public String getIdLocal()
    {
        return question.getIdLocal();
    }
    @Override // IQuestion
    public void setIdLocal(String idlocal)
    {
        question.setIdLocal(idlocal);
    }
    @Override // IQuestion
    public String getName()
    {
        return question.getName();
    }
    @Override // IQuestion
    public void setName(String name)
    {
        question.setName(name);
    }
    @Override // IQuestion
    public String getDescription()
    {
        return question.getDescription();
    }
    @Override // IQuestion
    public void setDescription(String description)
    {
        question.setDescription(description);
    }
    @Override // IQuestion
    public int getParentIdTopic()
    {
        return question.getParentIdTopic();
    }
    @Override // IQuestion
    public void setParentIdTopic(int parentidtopic)
    {
        question.setParentIdTopic(parentidtopic);
    }
    @Override // IQuestion
    public int getOrder()
    {
        return question.getOrder();
    }
    @Override // IQuestion
    public void setOrder(int order)
    {
        question.setOrder(order);
    }
    @Override // IQuestion
    public int getMinValue()
    {
        return question.getMinValue();
    }
    @Override // IQuestion
    public void setMinValue(int minvalue)
    {
        question.setMinValue(minvalue);
    }
    @Override // IQuestion
    public int getMaxValue()
    {
        return question.getMaxValue();
    }
    @Override // IQuestion
    public void setMaxValue(int maxvalue)
    {
        question.setMaxValue(maxvalue);
    }
    @Override // IQuestion
    public int getDefaultValue()
    {
        return question.getDefaultValue();
    }
    @Override // IQuestion
    public void setDefaultValue(int defaultvalue)
    {
        question.setDefaultValue(defaultvalue);
    }
    @Override // IQuestion
    public int getIsActive()
    {
        return question.getIsActive();
    }
    @Override // IQuestion
    public void setIsActive(int isactive)
    {
        question.setIsActive(isactive);
    }
    @Override // IQuestion
    public boolean isPrivate()
    {
        return question.isPrivate();
    }
    @Override // IQuestion
    public void setPrivate( boolean isPrivate )
    {
        question.setPrivate(isPrivate);
    }
    @Override // IQuestion
    public String getTextValue(int value) throws IllegalValueException
    {
        return question.getTextValue(value);
    }
    @Override // IQuestion
    public List<List<Object>> getListTextValues()
    {
        return question.getListTextValues();
    }
    @Override // IQuestion
    public void setListTextValues(List<List<Object>> textValues)
    {
        question.setListTextValues(textValues);
    }

    @Override
    public String toString()
    {
        return super.toString()
                + "Value [uservalue=" + this.getUserValue()
                + ", usercomment=" + this.getUserComment()
                + ", userdate=" + this.getUserDate()
                + ", userid=" + this.getIdUser()
                + "]";
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((question == null) ? 0 : question.hashCode());
        result = prime * result
                + ((userValue == null) ? 0 : userValue.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object obj )
    {
        if( this == obj ) {
            return true;
        }
        if( obj == null ) {
            return false;
        }
        if( !(obj instanceof QuestionValue) ) {
            return false;
        }
        QuestionValue other = (QuestionValue)obj;
        if( question == null ) {
            if( other.question != null ) {
                return false;
            }
        } else if( !question.equals( other.question ) ) {
            return false;
        }
        if( userValue == null ) {
            if( other.userValue != null ) {
                return false;
            }
        } else if( !userValue.equals( other.userValue ) ) {
            return false;
        }
        return true;
    }

}
